extern crate rand;

pub mod sort {

	use rand::{thread_rng};
	use rand::seq::SliceRandom;

	pub fn test() {
		sort_vec();
		sort_float_vec();
		sort_struct();
	}

	fn sort_vec() {
		let mut vec = vec![1,5,10,2,10,15];
		vec.sort();
		println!("sorted: {:?}", vec);
		
		let mut rng = thread_rng();
		vec.shuffle(&mut rng);

		println!("shuffle: {:?}", vec);
		vec.sort_unstable();
		println!("{:?}", vec);
	}

	fn sort_float_vec() {
		let mut vec = vec![1.1, 1.5, 5.5, 1.123, 2.0];
		vec.sort_by(|a,b| a.partial_cmp(b).unwrap());
		println!("sorted: {:?}", vec);
	}

	#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
	struct Person {
		name: String,
		age: u32,
	}

	impl Person {
		pub fn new(name: String, age: u32) -> Person {
			Person {
				name, age,
			}
		}
	}

	fn sort_struct(){
		let mut people = vec![
			Person::new("Zoe".to_string(), 25),
			Person::new("Al".to_string(), 60),
			Person::new("John".to_string(), 1),
		];

		people.sort();
		println!("default sort: {:?}", people);

		people.sort_by(|a,b| b.age.cmp(&a.age));

		println!("sort by age: {:?}", people);
	}

	
}